<template>
	<view class="coupon-info">
		<view v-for="(item, index) in list" :key="index">
			<view class="coupon-info-item">
				<view>
					<view class="content">
						<view class="page-group">
							<text class="fold-page"></text>
							<text class="page">{{ item.couponType == '1' ? '满减券' : '折扣券' }}</text>
						</view>
						<text class="dot-left"></text>
						<text class="dot-right"></text>
						<view class="coupon-detail">
							<view v-if="item.couponType == '2'">
								<text>{{ item.discount }}</text>
								<text>折</text>
							</view>
							<view v-else-if="item.couponType == '1'">
								<text>{{ item.amount }}</text>
								<text>元</text>
							</view>
							<view>
								<view style="font-size: 14px; font-weight: 700">
									{{ item.threshold > 0 ? '订单满' + item.threshold + '可以使用' : '无门槛优惠券' }}
								</view>
								<view style="font-size: 12px">{{ item.useRange == '1' ? '全部商品可用' : '指定商品可用' }}</view>
								<view style="font-size: 12px; color: #909090"> 有效期至{{ item.receiveEndedAt }} </view>
							</view>
							<view>
								<!-- 领取限制 -->
								<u-button
									v-if="item.userReceiveCount > 0"
									:disabled="item.receiveCount == item.userReceiveCount"
									size="mini"
									@click="onsubmit(item.id)"
									>{{ item.receiveCount == item.userReceiveCount ? '已领取' : '已领取' + item.userReceiveCount + '/' + item.receiveCount }}</u-button
								>
								<u-button v-else size="mini" @click="onsubmit(item.id)">立即领取</u-button>
							</view>
						</view>
					</view>
					<view class="u-padding-15">
						<view>使用说明</view>
						<view style="font-size: 12px">{{ item.useDescription }}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup lang="ts">
import { addObj } from '@/api/promotion/couponUser';
defineProps({
	list: {
		type: Array,
		default: [],
	},
});
const emit = defineEmits(['handleSuccess']);
const onsubmit = (id: string) => {
	addObj({ couponId: id }).then((response) => {
		uni.showToast({
			title: '领取成功',
			icon: 'success',
			duration: 2000,
		});
		emit('handleSuccess');
	});
};
</script>

<style lang="scss" scoped>
.coupon-info {
	margin: 40px 0px;
}
.coupon-info-item {
	overflow: hidden;
	margin: 10px;
	padding-left: 2px;
	position: relative;
}

.coupon-info-item > view {
	border: 1px solid #f2f2f2;
	background: #fff;
	border-radius: 10px;
}

.coupon-info-item .dot-left,
.coupon-info-item .dot-right {
	display: block;
	width: 12px;
	height: 12px;
	border-radius: 50%;
	background: #f5f5f5;
	position: absolute;
	z-index: 999;
}

.coupon-info-item .dot-left {
	bottom: -6px;
	left: -6px;
}

.coupon-info-item .dot-right {
	bottom: -6px;
	right: -6px;
}

.coupon-info-item .page-group {
	position: absolute;
	top: 10px;
	left: -2px;
	width: 100%;
	max-width: 120px;
}

.coupon-info-item .page-group .fold-page {
	display: block;
	width: 2px;
	height: 5px;
	background: #db0113;
	transform: skewY(-40deg);
	position: absolute;
	top: -1px;
	left: 0;
	z-index: 0;
}

.coupon-info-item .page-group .page {
	position: absolute;
	z-index: 1;
	display: block;
	padding: 0 10px;
	height: 20px;
	background: linear-gradient(137deg, #ff5b5b 0%, #db0113 100%);
	border-radius: 0 20px 20px 0;
	color: #fff;
	text-align: center;
	font-size: 12px;
	overflow: hidden;
}

.coupon-info-item .content {
	width: 100%;
	height: 90px;
	border-bottom: 1px dotted #f5f5f5;
	position: relative;
	z-index: 2;
}

.coupon-info-item .content .coupon-detail {
	display: flex;
	justify-content: space-between;
	padding: 0 15px 0 20px;
}

.coupon-info-item .content .coupon-detail > view {
	height: 90px;
	display: flex;
	justify-content: center;
	align-items: center;
}

.coupon-info-item .content .coupon-detail > view:first-child {
	color: #e21422;
	padding-top: 20px;
	width: 30%;
}

.coupon-info-item .content .coupon-detail > view:first-child > text:first-child {
	font-size: 28px;
}

.coupon-info-item .content .coupon-detail > view:first-child > text:last-child {
	font-size: 16px;
	padding: 9px 0 0;
}

.coupon-info-item .content .coupon-detail > view:last-child > view {
	color: #dd0d1f;
	border: 1px solid #dd0d1f;
	border-radius: 20px;
	font-size: 12px;
	display: flex;
	justify-content: center;
	align-items: center;
	width: 76px;
	height: 22px;
}

.coupon-info-item .coupon-detail > view:nth-child(2) {
	flex-direction: column;
	padding-top: 5px;
}

.coupon-info-item .coupon-detail > view:nth-child(2) > view {
	width: 100%;
}

.coupon-info-item .ribbon {
	width: 80px;
	height: 20px;
	background: #dd0d1f;
	position: absolute;
	right: -20px;
	top: 10px;
	transform: rotateZ(45deg);
	text-align: center;
	color: #fff;
	font-size: 12px;
}

</style>
